﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    class SQLHelper
    {
        // 静态字段
        static String connetStr = "server=localhost;port=3306;user id=root;password=root; database=mydb";
        public static object ExecuteScalar(string sql) {
         
            MySqlConnection conn = new MySqlConnection(connetStr);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            Object result = cmd.ExecuteScalar();
            return result;
        }
        public static int ExecuteNonQuery(string sql)
        {
           // String connetStr = "server=localhost;port=3306;user id=root;password=root; database=mydb";
            MySqlConnection conn = new MySqlConnection(connetStr);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            int result = cmd.ExecuteNonQuery();
            return result;
        }
    }
}
